#!/bin/bash

apt -y update
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL "http://mirrors.cloud.aliyuncs.com/docker-ce/linux/$(lsb_release -is | tr 'A-Z' 'a-z')/gpg" | sudo apt-key add -
add-apt-repository "deb [arch=amd64] http://mirrors.cloud.aliyuncs.com/docker-ce/linux/$(lsb_release -is | tr 'A-Z' 'a-z') $(lsb_release -cs) stable"
apt -y update
apt -y install docker-ce python3-pip
pip3 install --upgrade pip
pip3 install docker-compose

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://ddws17xl.mirror.aliyuncs.com",
    "https://reg-mirror.qiniu.com",
    "https://hub-mirror.c.163.com",
    "https://mirror.ccs.tencentyun.com",
    "http://f1361db2.m.daocloud.io",
    "https://dockerhub.azk8s.cn",
    "https://docker.mirrors.ustc.edu.cn",
    "https://registry.docker-cn.com"
  ],
  "log-driver":"json-file",
  "log-opts": {"max-size":"500m", "max-file":"3"},
  "ipv6": true,
  "fixed-cidr-v6": "fc00:17:1:1::/64",
  "experimental": true,
  "ip6tables": true
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

ip6tables -t nat -A POSTROUTING -s fc00:17:1:1::/64 -j MASQUERADE
ip6tables -t nat -L

sudo systemctl restart docker

#docker run --rm -it busybox ping -6 -c4 ipv6-test.com
#docker network create -d bridge --ipv6 --subnet "fc00:18:1:1:0:1::/80" --gateway="fc00:18:1:1::1" nginx
#docker network inspect bridge, 参考定义ipv6自定义网络gateway和subnet(本脚本例子中为fc00:17:1:1::/64, fc00:17:1:1::1)


#ref: https://zhuanlan.zhihu.com/p/342633966 docker 容器开启ipv6
#ref: http://ylong.net.cn/docker-ipv6.html Docker开启IPv6
#ref: https://www.cnblogs.com/greencollar/p/13502628.html Docker IPv6 网络环境配置 
#ref: https://blog.csdn.net/taiyangdao/article/details/83066009 Docker容器支持IPv6的方法
